import { Controller, Get, Post, Body, Patch, Param, Delete, DefaultValuePipe, ParseIntPipe, Query, SetMetadata } from '@nestjs/common';
import { TaskService } from './task.service';
import { CreateTaskDto } from './dto/create-task.dto';
import { UpdateTaskDto } from './dto/update-task.dto';
import { ReflectMetadataKeys } from '@/common/enum/ReflectMetadataKeys';
import { taskQueryVo } from '@/common/interface';
import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger';
import { Task } from './entities/task.entity';


@ApiTags('任务大厅')
@Controller('task')
export class TaskController {
  constructor(private readonly taskService: TaskService) {}

  @ApiOperation({ summary: '任务创建' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '任务创建')
  @Post()
  create(@Body() createTaskDto: CreateTaskDto) {
    return this.taskService.create(createTaskDto);
  }

  @ApiOperation({ summary: '任务列表' })
  @ApiResponse({ status: 200, description: '200', type: [Task] })
  @ApiQuery({
    name: 'name',
    required: false,
    description: '任务名称',
    type: String,
  })
  @ApiQuery({
    name: 'queryDate',
    required: false,
    description: '查询时间',
    type: Array
  })
  @ApiQuery({
    name: 'page',
    required: false,
    description: '第几页',
    type: Number,
    example: 1
  })
  @ApiQuery({
    name: 'limit',
    required: false,
    description: '每页显示数',
    type: Number,
    example: 10
  })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '任务列表')
  @Get()
  findAll(
    @Query() query: taskQueryVo,
    @Query('page', new DefaultValuePipe(1), ParseIntPipe) page = 1,
    @Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit = 10
  ) {
    return this.taskService.findAll({ page, limit }, query);
  }

  @ApiOperation({ summary: '任务详情' })
  @ApiResponse({ status: 200, description: 'success', type: Task })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '任务详情')
  @Get(':id')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.taskService.findOne(id);
  }

  @ApiOperation({ summary: '修改任务' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '修改任务')
  @Patch()
  update(@Body() updateTaskDto: UpdateTaskDto) {
    return this.taskService.update(updateTaskDto);
  }

  @ApiOperation({ summary: '删除任务' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '删除任务')
  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.taskService.remove(id);
  }
}
